#include "GlobalVertex.h"

LPDIRECT3DVERTEXDECLARATION9 VPos::declaration = NULL;
LPDIRECT3DVERTEXDECLARATION9 VPosTex1::declaration = NULL;
LPDIRECT3DVERTEXDECLARATION9 VPosTex1Tan::declaration = NULL;

void CreateAllVertexDeclarations(LPDIRECT3DDEVICE9 pDevice)
{
	D3DVERTEXELEMENT9 tVP[] = 
	{
		{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};	
	pDevice->CreateVertexDeclaration(tVP, &VPos::declaration);

	//////////////////////////////////////////////////////////////////////////

	D3DVERTEXELEMENT9 tVPosTex1[] = 
	{
		{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
		{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		D3DDECL_END()
	};	
	pDevice->CreateVertexDeclaration(tVPosTex1, &VPosTex1::declaration);

	//////////////////////////////////////////////////////////////////////////

	D3DVERTEXELEMENT9 tVPosTex1Tan[] = 
	{
		{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
		{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		{0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
		D3DDECL_END()
	};	
	pDevice->CreateVertexDeclaration(tVPosTex1Tan, &VPosTex1Tan::declaration);

	//////////////////////////////////////////////////////////////////////////
}

void DeleteAllVertexDeclarations()
{
	if(VPos::declaration != NULL)
	{
		VPos::declaration->Release();
		VPos::declaration = NULL;
	}

	if(VPosTex1::declaration != NULL)
	{
		VPosTex1::declaration->Release();
		VPosTex1::declaration = NULL;
	}

	if(VPosTex1Tan::declaration != NULL)
	{
		VPosTex1Tan::declaration->Release();
		VPosTex1Tan::declaration = NULL;
	}
}